package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.RelationImplDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RelationImplMapper {
    
    @Select("SELECT * FROM relation_impl WHERE id = #{id}")
    RelationImplDO findById(@Param("id") Long id);
    
    @Select("SELECT * FROM relation_impl WHERE semantic_network_id = #{semanticNetworkId}")
    List<RelationImplDO> findBySemanticNetworkId(@Param("semanticNetworkId") Long semanticNetworkId);
    
    @Select("SELECT * FROM relation_impl WHERE relation_item_id = #{relationItemId}")
    List<RelationImplDO> findByRelationItemId(@Param("relationItemId") Long relationItemId);
    
    @Insert("INSERT INTO relation_impl(semantic_network_id, relation_item_id, impl_str, create_time, update_time) " +
            "VALUES(#{semanticNetworkId}, #{relationItemId}, #{implStr}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(RelationImplDO relationImplDO);
    
    @Update("UPDATE relation_impl SET semantic_network_id = #{semanticNetworkId}, " +
            "relation_item_id = #{relationItemId}, impl_str = #{implStr}, update_time = NOW() WHERE id = #{id}")
    int update(RelationImplDO relationImplDO);
    
    @Delete("DELETE FROM relation_impl WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
    
    @Delete("DELETE FROM relation_impl WHERE semantic_network_id = #{semanticNetworkId}")
    int deleteBySemanticNetworkId(@Param("semanticNetworkId") Long semanticNetworkId);
    
    @Delete("DELETE FROM relation_impl WHERE relation_item_id = #{relationItemId}")
    int deleteByRelationItemId(@Param("relationItemId") Long relationItemId);
} 